package com.yczy365.petmall.web;

import com.yczy365.petmall.ex.ServiceException;
import lombok.Data;

@Data
public class JsonResult {
    private String message;
    private Integer state;
    public static JsonResult fail(ServiceCode serviceCode,String message){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setState(serviceCode.getValue());
        jsonResult.setMessage(message);
        return jsonResult;

    }
    public static JsonResult ok(){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setState(ServiceCode.OK.getValue());
        return jsonResult;

    }
    public static JsonResult fail(ServiceException serviceException ){
       return fail(serviceException.getServiceCode(),serviceException.getMessage());

    }
}
